package com.example.liu_test.service.impl;

import com.baomidou.mybatisplus.extension.api.R;
import com.example.liu_test.pojo.RespBean;
import com.example.liu_test.pojo.User;
import com.example.liu_test.mapper.UserMapper;
import com.example.liu_test.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.liu_test.service.UserVoService;
import javassist.bytecode.ExceptionsAttribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 刘旺
 * @since 2021-07-06
 */
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Autowired
    private UserMapper userMapper;

    /**
     * @param
     * @author lw
     */
    @Override
    public RespBean delete(String id)  {

        if(userMapper.deleteById(id)!=1) {
            return RespBean.error("删除失败");
        }
            return RespBean.success("删除成功");
    }

    @Override
    public RespBean insertUser(User user) {
        int insert = userMapper.insert(user);
        if(insert==0){
            return RespBean.error("插入失败");
        }
        return RespBean.success("success");

    }

    @Override
    public RespBean updateUser(User user) {
        int i = userMapper.updateById(user);
        if(i != 1){
            return RespBean.error("更新失败");
        }
        return RespBean.success("更新成功");
    }

    @Override
    public void sqlDelete(String userId) {

        userMapper.sqlDelete(userId);

    }
}